home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-11 | 39.8 KB | 1,413 lines | [TEXT/MPS ] |
- /*
- File: DrawContent.cpp
-
- Contains: Content Classes Implementation
-
- Written by: Dave Stafford.
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- */
-
- // -- DrawEditor Includes --
-
- #ifndef _DRAWCONTENT_
- #include "DrawContent.h"
- #endif
-
- #ifndef _COMPILERDEFS_
- #include "CompDefs.h"
- #endif
-
- #ifndef _DRAWEDTORUTILS_
- #include "DrawEditorUtils.h"
- #endif
-
- #ifndef _DRAWEDITOR_
- #include "DrawEditor.h"
- #endif
-
- #ifndef _SHAPECOMMANDS_
- #include "ShapeCommands.h"
- #endif
-
- #ifndef _SHAPES_
- #include "Shapes.h"
- #endif
-
- #ifndef _LINK_
- #include "Link.h"
- #endif
-
- #ifndef _SELECTION_
- #include "Selection.h"
- #endif
-
- // -- OpenDoc Includes --
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODFrameFacetIterator_xh
- #include "FrFaItr.xh"
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _STDTYPIO_
- #include "StdTypIO.h"
- #endif
-
- #ifndef _ODUTILS_
- #include "ODUtils.h"
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef _FOCUSLIB_
- #include "FocusLib.h"
- #endif
-
- #ifndef _ORDCOLL_
- #include "OrdColl.h"
- #endif
-
- #ifndef _ODMEMORY_
- #include "ODMemory.h"
- #endif
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h"
- #endif
-
- // -- Toolbox Includes --
-
- #ifndef mathRoutinesIncludes
- #include <math routines.h>
- #endif
-
- #ifndef __MEMORY__
- #include <memory.h>
- #endif
-
- #ifndef __DRAG__
- #include <Drag.h>
- #endif
-
- //=============================================================================
- // CDrawContent
- //=============================================================================
-
-
- //-----------------------------------------------------------------------------
- // CDrawContent::CDrawContent
- //-----------------------------------------------------------------------------
-
- CDrawContent::CDrawContent(DrawEditor* editor, COrderedList* shapes, COrderedList* pLinks, COrderedList* sLinks)
- {
- fDrawEditor = editor;
-
- fShapeList = shapes;
- fPublishLinks = pLinks;
- fSubscribeLinks = sLinks;
- }
-
-
- CDrawContent::CDrawContent(DrawEditor* editor)
- {
- fDrawEditor = editor;
-
- fShapeList = kODNULL;
- fPublishLinks = kODNULL;
- fSubscribeLinks = kODNULL;
-
- }
-
- //-----------------------------------------------------------------------------
- // CDrawContent::~CDrawContent
- //-----------------------------------------------------------------------------
-
- CDrawContent::~CDrawContent()
- {
- }
-
-
- //-----------------------------------------------------------------------------
- // CDrawContent::GetDrawEditor
- //-----------------------------------------------------------------------------
-
- DrawEditor* CDrawContent::GetDrawEditor() const
- {
- return fDrawEditor;
- }
-
-
- //-----------------------------------------------------------------------------
- // CDrawContent::GetShapeList
- //-----------------------------------------------------------------------------
-
- COrderedList* CDrawContent::GetShapeList() const
- {
- return fShapeList;
- }
-
-
- //-----------------------------------------------------------------------------
- // CDrawContent::RemoveShape
- //-----------------------------------------------------------------------------
-
-
-
-
- //-----------------------------------------------------------------------------
- // CDrawContent::Externalize
- //-----------------------------------------------------------------------------
-
- void CDrawContent::Externalize(Environment* ev,
- ODStorageUnit* storage,
- CCloneInfo* info)
- {
- ODBoolean weBeganClone = kODFalse;
-
- // Externalize the content
- TRY
- ODDraft* dstDraft = storage->GetDraft(ev);
- // If there is clone info then begin a clone
- if (info && info->fKey==kODNULL)
- {
- info->fKey = info->fFromDraft->
- BeginClone(ev, dstDraft, info->fScopeFrame, info->fCloneKind);
- weBeganClone = kODTrue;
- }
-
- // Write the number of shapes
- ODUShort count = fShapeList->Count();
-
- StorageUnitSetValue(storage, ev, sizeof(ODUShort), &count);
-
- // Write the shapes Tag each one with it's 'externalization index'
- ODUShort extInd = 0;
-
- COrdListIterator iter(fShapeList);
- for ( CShape* shape = (CShape*)iter.First();
- iter.IsNotComplete();
- shape = (CShape*)iter.Next() )
- {
- // Write the shape type
- ODSShort type = shape->GetShapeType();
- StorageUnitSetValue(storage, ev, sizeof(ODSShort), &type);
-
- // Write the shape
- shape->Write(ev, storage, info);
-
- // Tag shape with an index for use by links.
- shape->SetExternalizationIndex(extInd++);
- }
-
- this->ExternalizeLinks(ev, storage, info);
-
- if (weBeganClone)
- info->fFromDraft->EndClone(ev, info->fKey);
-
- CATCH_ALL
- // Abort clone operation
- if (weBeganClone)
- info->fFromDraft->AbortClone(ev, info->fKey);
-
- RERAISE;
- ENDTRY
- }
-
- //-----------------------------------------------------------------------------
- // CDrawContent::ExternalizeSingleEmbeddedFrame
- //-----------------------------------------------------------------------------
-
- void CDrawContent::ExternalizeSingleEmbeddedFrame(Environment* ev,
- ODStorageUnit* storage,
- CCloneInfo* info,
- ODFrame* embeddedFrame)
- {
- // We should not be calling this method without valid clone info
- THROW_IF_NULL(info);
-
- ODVolatile(info->fKey);
-
- TRY
-
- // Start a clone operation
- if (info->fKey==kODNULL)
- info->fKey = info->fFromDraft->BeginClone(ev,
- storage->GetDraft(ev),
- info->fScopeFrame,
- info->fCloneKind);
-
- // Add the content frame property now, but don't clone the
- // frame until after the part is cloned
- storage->AddProperty(ev, kODPropContentFrame);
- storage->AddValue(ev, kODWeakStorageUnitRef);
-
- // Write a kODPropCloneKind so that any embedded shape which chooses
- // to promise can record the cloneKind for use when fulfilling the promise. Otherwise,
- // a link update of a single embedded frame which promises in CloneInto, will fail
- // when the promise is fulfilled due to using the wrong cloneKind.
-
- // This property/value must be provided so that an embedded frame which writes
- // a promise within our clone block, can fulfill that promise using the same cloneKind
-
- storage->AddProperty(ev, kODPropCloneKindUsed);
- storage->AddValue(ev, kODCloneKind);
- StorageUnitSetValue(storage, ev, sizeof(ODCloneKind), &info->fCloneKind);
-
- // Clone the embedded part
- ODPart* embeddedPart = embeddedFrame->AcquirePart(ev);
-
- info->fFromDraft->Clone(ev,
- info->fKey,
- embeddedPart->GetID(ev),
- storage->GetID(ev),
- embeddedFrame->GetID(ev));
- ODReleaseObject(ev, embeddedPart);
-
- // Clone the embedded frame to storage; must be done AFTER the part
- // is cloned because the frame strongly references the part
- ODID toFrameID = info->fFromDraft->Clone(ev,
- info->fKey,
- embeddedFrame->GetID(ev), 0,
- embeddedFrame->GetID(ev));
-
- // Weakly reference the frame so it must be explicitly cloned
- // into the receiving draft
- ODSUForceFocus(ev, storage, kODPropContentFrame, kODWeakStorageUnitRef);
- ODStorageUnitRef aSURef;
- storage->GetWeakStorageUnitRef(ev, toFrameID, aSURef);
- StorageUnitSetValue(storage, ev, sizeof(ODStorageUnitRef), aSURef);
-
- this->ExternalizeSingleFrameLinks(ev, storage, info);
-
- info->fFromDraft->EndClone(ev, info->fKey);
-
- CATCH_ALL
- info->fFromDraft->AbortClone(ev, info->fKey);
- RERAISE;
-
- ENDTRY
-
-
- }
-
- //-----------------------------------------------------------------------------
- // CDrawContent::Internalize
- //-----------------------------------------------------------------------------
-
- void CDrawContent::Internalize(Environment* ev,
- ODStorageUnit* storageUnit,
- CCloneInfo* info)
- {
-
- ODDraft* dstDraft = fDrawEditor->GetDraft(ev);
-
- if (storageUnit->Exists(ev, kODPropContents, fDrawEditor->GetEditorKind(), 0))
- {
- CShape** shapeTable = kODNULL;
- ODVolatile(shapeTable);
- ODBoolean weBeganClone = kODFalse;
-
- TRY
-
- // Start a clone operation, if necessary
- if (info && info->fKey==kODNULL)
- {
- ODDraftKey key = info->fFromDraft->BeginClone(ev, dstDraft, info->fScopeFrame, info->fCloneKind);
- info->fKey = key;
- weBeganClone = kODTrue;
- }
-
- // focus
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, fDrawEditor->GetEditorKind(), 0, kODPosUndefined);
-
- // Read the tag constant identifying this as a selection
- // as opposed to a complete document
- ODSShort tag;
- StorageUnitGetValue(storageUnit, ev, sizeof(ODSShort), &tag);
-
- // Read the document header data, if it exists
- if (tag==kDrawDocument)
- {
- // Here you would read document header data. That is, data that is would
- // normally be written out during an interchange operation, rather it is
- // only written out when the document is saved as a whole.
- }
-
- // Read number of shapes
- ODUShort count;
- StorageUnitGetValue(storageUnit, ev, sizeof(ODUShort), &count);
-
- shapeTable = new CShape*[count];
-
- // Temp storage for internalized shapes
- COrderedList tCollection;
-
- //Then read in the new selection
- for (ODUShort i = 0; i<count; i++)
- {
- // Read the shape type
- ODSShort type;
- StorageUnitGetValue(storageUnit, ev, sizeof(ODSShort), &type);
-
- // Create a new shape
- CShape* shape = fDrawEditor->CreateShape(ev, type);
- if (shape != kODNULL)
- {
- // Read the shape
- shape->Read(ev, storageUnit, info);
-
- tCollection.AddFirst(shape);
-
- }
- shapeTable[i] = shape;
- }
-
- // There are NEVER any links to be found when we transfer data from a link
- // This test avoids executing all this code just to find out what is already
- // known.
-
- if (info->fCloneKind != kODCloneFromLink) // testing for non-null link lists would also be valid
- {
- // If this is the case of incorporating the content of a single embedded frame
- // then first deal with any subscribe link that was associated with the original
- // frame. Then deal with any subscribe links associated with it's content
- // then deal with any publish link from the frame, then with any publish links
- // for the content. We have to get all the subscribers before any publishers
- // because any shapes that are subscribed should end up pointing to the subscribe
- // link rather than to a publishers, so doing the subscribers first avoids a lot of
- // cleanup code later.
-
- ODBoolean wasEmbedded = storageUnit->Exists(ev, kODPropContentFrame, kODWeakStorageUnitRef, 0);
- ODULong contentFrameOffset = 0;
-
- if (wasEmbedded)
- {
- // we have to shift focus to kODPropContentFrame, need to know where to resume reading
- // kODPropContents when done. Could use an ODStorageUnitCursor if I knew how
-
- ODULong offset = storageUnit->GetOffset(ev);
- this->MergeSingleFrameSubLink(ev, storageUnit, info, &tCollection, contentFrameOffset);
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, fDrawEditor->GetEditorKind(), 0, kODPosUndefined);
- storageUnit->SetOffset(ev, offset);
- }
-
- this->InternalizeSubLinks(ev, storageUnit, info, shapeTable);
-
- if (wasEmbedded)
- {
- ODULong offset = storageUnit->GetOffset(ev);
- this->MergeSingleFramePubLink(ev, storageUnit, info, &tCollection, contentFrameOffset);
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, fDrawEditor->GetEditorKind(), 0, kODPosUndefined);
- storageUnit->SetOffset(ev, offset);
- }
-
- this->InternalizePubLinks(ev, storageUnit, info, shapeTable);
- }
-
- if (weBeganClone)
- {
- info->fFromDraft->EndClone(ev, info->fKey);
- info->fKey = 0;
- }
-
- // Can only add shapes to content after the clone has ended
- // because GetFrame can only be called after a clone is complete.
- // Since our shapes may be embedded content, we have to wait.
- COrdListIterator iter(&tCollection);
- for (CShape *shape = (CShape*)iter.First();
- iter.IsNotComplete();
- shape = (CShape*)iter.Next())
- {
- this->AddShapeToPart(ev, shape);
-
- // Add it to content
- this->AddShape(ev, shape);
- }
-
- this->PostCloneInternalizeLinks(ev, kODNULL);
-
- CATCH_ALL
- if (weBeganClone)
- {
- if (info->fKey != 0)
- info->fFromDraft->AbortClone(ev, info->fKey);
- }
-
- if (shapeTable)
- delete shapeTable;
-
- ENDTRY
- }
- else
- {
- DebugStr("\pStorage unit should have a content property here.");
- }
-
- }
-
- //-----------------------------------------------------------------------------
- // CDrawContent::InternalizeSingleEmbeddedFrame
- //-----------------------------------------------------------------------------
-
- void CDrawContent::InternalizeSingleEmbeddedFrame(Environment* ev,
- ODStorageUnit* storageUnit,
- CCloneInfo* info)
- {
- ODDraft* toDraft = fDrawEditor->GetDraft(ev);
- ODID newFrameID = 0;
- ODID newPartID = 0;
- ODPart* newPart = kODNULL;
- Rect tShapeRect;
- ODBoolean weBeganClone = kODFalse;
-
- TRY
- // Gotta be cloning in this case
- THROW_IF_NULL(info);
-
- // Start a clone operation, if necessary
- if (info->fKey==kODNULL)
- {
- info->fKey = info->fFromDraft->BeginClone(ev, toDraft, info->fScopeFrame, info->fCloneKind);
- weBeganClone = kODTrue;
- }
-
- // Clone the part
- ODID newPartID = info->fFromDraft->Clone(ev, info->fKey, storageUnit->GetID(ev), kODNULLID, kODNULLID);
-
- // If there is a content frame then use it
- if (ODSUExistsThenFocus(ev, storageUnit, kODPropContentFrame, kODWeakStorageUnitRef))
- {
- // Clone the frame
- ODStorageUnitRef aSURef;
- StorageUnitGetValue(storageUnit, ev, sizeof(aSURef), aSURef);
-
- if (storageUnit->IsValidStorageUnitRef(ev, aSURef))
- {
- ODID storageUnitID = storageUnit->GetIDFromStorageUnitRef(ev, aSURef);
- newFrameID = info->fFromDraft->Clone(ev, info->fKey, storageUnitID, 0, 0);
- }
- else
- THROW(kODErrInvalidStorageUnitRef);
-
- this->InternalizeSingleEmbeddedFrameLinks(ev, storageUnit, info);
-
- }
- else
- // otherwise, use the suggested frame shape
- if (ODSUExistsThenFocus(ev, storageUnit, kODPropSuggestedFrameShape, kODNULL))
- {
- ODShape* tShape = info->fScopeFrame->CreateShape(ev);
- tShape->ReadShape(ev, storageUnit);
- ODRgnHandle tODRegion = tShape->GetQDRegion(ev);
- tShapeRect = (*tODRegion)->rgnBBox;
-
- // Release acquired geometry
- ODReleaseObject(ev, tShape);
- }
- else
- {
- DebugStr("\pStorage unit needs content frame of shape here.");
- }
-
- // End the clone operation
- if (weBeganClone)
- {
- info->fFromDraft->EndClone(ev, info->fKey);
- info->fKey = 0;
- }
-
- // Get the part
- newPart = toDraft->AcquirePart(ev, newPartID);
- THROW_IF_NULL(newPart);
-
- // Create a shape.
- CEmbeddingShape* tShape = (CEmbeddingShape*)(fDrawEditor->CreateShape(ev, kEmbeddingShape));
- THROW_IF_NULL(tShape);
-
- // Size the shape if we read the suggested frame shape property
- if (newFrameID==0)
- {
- tShape->SetBoundingBox(ev, tShapeRect);
- }
-
- // Embed it
- tShape->Embed(ev, newPart, info->fScopeFrame, newFrameID);
-
- // Add the shape to the part's content list
- this->AddShapeToPart(ev, tShape);
-
- // Add the shape to this content object
- this->AddShape(ev, tShape);
-
- this->PostCloneInternalizeLinks(ev, tShape);
-
- // Release acquired part
- ODReleaseObject(ev, newPart);
-
- CATCH_ALL
- // Something is amiss, abort the clone
- if (weBeganClone && info->fKey!=0)
- info->fFromDraft->AbortClone(ev, info->fKey);
-
- // Release acquired part
- ODSafeReleaseObject(newPart);
-
- RERAISE;
- ENDTRY
-
- }
-
- //-----------------------------------------------------------------------------
- // CDrawContent::IsOneEmbeddedShape
- // This method returns the shape if there is only one embedded shape in
- // the selection, otherwise kODNULL is returned.
- //-----------------------------------------------------------------------------
-
- CEmbeddingShape* CDrawContent::IsOneEmbeddedShape(Environment* ev) const
- {
- // If there is only one shape and there is one embedding shape
- // then return the shape, oltherwise return kODNULL
- if (fShapeList->Count() ==1)
- {
- CShape* shape = (CShape *)fShapeList->First();
- if (shape && (shape->GetShapeType() == kEmbeddingShape))
- return (CEmbeddingShape*)shape;
- }
-
- return kODNULL;
- }
-
-
- //-----------------------------------------------------------------------------
- // CDrawContent::GetPublishLinks
- //-----------------------------------------------------------------------------
-
- COrderedList* CDrawContent::GetPublishLinks() const
- {
- return fPublishLinks;
- }
-
-
- //-----------------------------------------------------------------------------
- // CDrawContent::GetSubscribeLinks
- //-----------------------------------------------------------------------------
-
- COrderedList* CDrawContent::GetSubscribeLinks() const
- {
- return fSubscribeLinks;
- }
-
- //-----------------------------------------------------------------------------
- // CDrawContent::HandleInternalizeContent
- //-----------------------------------------------------------------------------
-
- void CDrawContent::HandleInternalizeContent(Environment* ev,
- ODStorageUnit* storage,
- CCloneInfo* info)
- {
- // Is it a single embedded frame?
- if (storage->Exists(ev, kODPropContentFrame, kODWeakStorageUnitRef, 0))
- {
- this->InternalizeSingleEmbeddedFrame(ev, storage, info);
- }
- else
- // Is it our native kind?
- if (storage->Exists(ev, kODPropContents, kDrawEditorKind, 0))
- {
- storage->Focus(ev, kODPropContents, kODPosUndefined, kDrawEditorKind, 0, kODPosFirstSib);
- this->Internalize(ev, storage, info);
- }
- else
- // We don't know what it is, try to embed
- if (storage->Exists(ev, kODPropContents, kODNULL, 0))
- {
- storage->Focus(ev, kODPropContents, kODPosUndefined, kODNULL, 0, kODPosFirstSib);
- this->InternalizeForeignContent(ev, storage, info);
- }
-
- }
-
-
- //-----------------------------------------------------------------------------
- // CDrawContent::HandleTranslateContent
- //-----------------------------------------------------------------------------
-
- void CDrawContent::HandleTranslateContent(Environment* ev,
- ODStorageUnit* storage,
- CCloneInfo* info,
- ODBoolean doEmbed)
- {
-
- ODBoolean canMerge = storage->Exists(ev, kODPropContents, kDrawEditorKind, 0);
-
- // Is it a single embedded frame?
- if (storage->Exists(ev, kODPropContentFrame, kODWeakStorageUnitRef, 0))
- {
- // Merge if we're forcing a merge and content can be merged.
- if (doEmbed || !canMerge)
- this->InternalizeSingleEmbeddedFrame(ev, storage, info);
- else
- this->Internalize(ev, storage, info);
- }
- else
- // Is it our native kind? And are we not forcing embed?
- if (canMerge && !doEmbed)
- {
- storage->Focus(ev, kODPropContents, kODPosUndefined, kDrawEditorKind, 0, kODPosFirstSib);
-
- this->Internalize(ev, storage, info);
- }
- else
- // We don't know what it is, or we are forcing embed = try to embed
- if (storage->Exists(ev, kODPropContents, kODNULL, 0))
- {
- storage->Focus(ev, kODPropContents, kODPosUndefined, kODNULL, 0, kODPosFirstSib);
-
- this->InternalizeForeignContent(ev, storage, info);
- }
-
- }
-
-
- //-----------------------------------------------------------------------------
- // CDrawContent::InternalizeForeignContent
- //-----------------------------------------------------------------------------
-
- void CDrawContent::InternalizeForeignContent(Environment* ev,
- ODStorageUnit* contentSU,
- CCloneInfo* info)
- {
- // Prepare to clone the item
- ODDraft* fromDraft = contentSU->GetDraft(ev);
- ODDraft* toDraft = fDrawEditor->GetDraft(ev);
-
- ODID newPartID;
- ODID newFrameID = kODNULL;
- ODShape* newFrameShape = kODNULL;
-
- // These variables are used in a catch block, and so must be
- // declared volatile
- ODVolatile(info);
- ODVolatile(fromDraft);
-
- TRY
- // Clone the root storage unit
- info->fKey = fromDraft->BeginClone(ev, toDraft, info->fScopeFrame, info->fCloneKind);
-
- newPartID = fromDraft->Clone(ev, info->fKey, contentSU->GetID(ev), 0, 0);
-
- // If a frame already exists for this part then clone it too.
- if (contentSU->Exists(ev, kODPropContentFrame, kODWeakStorageUnitRef, 0))
- {
- ODStorageUnitRef aSURef;
- contentSU->Focus(ev, kODPropContentFrame, kODPosSame, kODWeakStorageUnitRef, 0, kODPosUndefined);
- StorageUnitGetValue(contentSU, ev, sizeof(ODStorageUnitRef), aSURef);
- if ( contentSU->IsValidStorageUnitRef(ev, aSURef) )
- newFrameID = fromDraft->Clone(ev, info->fKey, contentSU->GetIDFromStorageUnitRef(ev, aSURef), 0, 0);
- else
- DebugStr("\p Invalid reference to content frame\n");
- }
-
- fromDraft->EndClone(ev, info->fKey);
-
- CATCH_ALL
- if (info->fKey!=0)
- fromDraft->AbortClone(ev, info->fKey);
- ENDTRY
-
- // Cloning is done, now embed the part
- ODPart* newPart = toDraft->AcquirePart(ev, newPartID);
- THROW_IF_NULL(newPart);
-
- // Create a content shape
- CShape* newShape = fDrawEditor->CreateShape(ev, kEmbeddingShape);
-
- // We need a shape for the shape ( hee hee )
- // If a frame was not provided then see if there is a suggested frame shape
- if (newFrameID==kODNULL)
- {
- newFrameShape = info->fScopeFrame->CreateShape(ev);
- THROW_IF_NULL(newFrameShape);
-
- if (contentSU->Exists(ev, kODPropSuggestedFrameShape, kODNULL, 0))
- {
- contentSU->Focus(ev, kODPropSuggestedFrameShape, kODPosUndefined, NULL, 1, kODPosUndefined);
- newFrameShape->ReadShape(ev, contentSU);
- }
- else
- {
- // $$$$$ Need constant
- ODRect tRect(ff(0), ff(0), ff(80), ff(80));
-
- newFrameShape->SetRectangle(ev, &tRect);
- }
-
-
- // Size the shape
- newShape->SetBoundingBox(ev, newFrameShape);
-
- // Release acquired geometry
- ODReleaseObject(ev, newFrameShape);
- }
- else
- {
- ODFrame* frame = toDraft->AcquireFrame(ev, newFrameID);
- ODShape* frameShape = frame->AcquireFrameShape(ev, kODNULL);
-
- // Size the shape
- newShape->SetBoundingBox(ev, frameShape);
- }
-
- // Embed the part, CEmbeddingShape::Embed will release the part passed to it.
- ((CEmbeddingShape*)newShape)->Embed(ev, newPart, info->fScopeFrame, newFrameID);
-
- // Release the newly created part
- ODReleaseObject(ev, newPart);
-
- // Add the shape to the content list
- this->AddShapeToPart(ev, newShape);
-
- // Add the shape to the selection
- this->AddShape(ev, newShape);
- }
-
-
- #pragma segment Main
- void CDrawContent::AddPublishLink(CPublishLink* link)
- {
- fPublishLinks->AddLast(link);
- }
-
-
- #pragma segment Main
- void CDrawContent::AddSubscribeLink(CSubscribeLink* link)
- {
- fSubscribeLinks->AddLast(link);
- }
-
-
- #pragma segment Main
- void CDrawContent::RemoveSubscribeLink(CSubscribeLink* link)
- {
- fSubscribeLinks->Remove(link);
- }
-
-
- #pragma segment Main
- void CDrawContent::RemovePublishLink(CPublishLink* link)
- {
- fPublishLinks->Remove(link);
- }
-
-
- #pragma segment Main
- ODULong CDrawContent::Count()
- {
- return fShapeList->Count();
- }
-
-
- #pragma segment Main
- void CDrawContent::ExternalizeLinks(Environment *ev, ODStorageUnit *su, CCloneInfo *info)
- {
- // This test is for efficiency. If we skip the test, then for kODCloneToLink, OpenDoc will return an invalid
- // ID for each link when we try to clone it, and ExternalizeLink will write out an invalid shape count (0),
- // which will indicate that no link is available when internalization takes place.
-
- if (!info || info->fCloneKind != kODCloneToLink)
- {
- // If this is not a publish link's content, then it should have been instantiated from a
- // selection, and have at least empty link lists
-
- ASSERT_NOT_NULL(fSubscribeLinks);
- ASSERT_NOT_NULL(fPublishLinks);
-
- // Write out the subscribers first so that they can be internalized first
-
- ODUShort subCount = fSubscribeLinks->Count();
- StorageUnitSetValue(su, ev, sizeof(ODUShort), &subCount);
-
- COrdListIterator sIter(fSubscribeLinks);
- for (CSubscribeLink* sLink = (CSubscribeLink*)sIter.First(); sIter.IsNotComplete(); sLink = (CSubscribeLink*)sIter.Next())
- {
- sLink->ExternalizeLink(ev, su, info);
- }
-
- // Write out the publishers last.
-
- ODUShort pubCount = fPublishLinks->Count();
- StorageUnitSetValue(su, ev, sizeof(ODUShort), &pubCount);
-
- COrdListIterator pIter(fPublishLinks);
- for (CPublishLink* pLink = (CPublishLink*)pIter.First(); pIter.IsNotComplete(); pLink = (CPublishLink*)pIter.Next())
- {
- pLink->ExternalizeLink(ev, su, info);
- }
-
- }
- else
- {
- ODUShort noLinks = 0;
- StorageUnitSetValue(su, ev, sizeof(ODUShort), &noLinks);
- StorageUnitSetValue(su, ev, sizeof(ODUShort), &noLinks);
- }
-
- }
-
-
- #pragma segment Main
- void CDrawContent::ExternalizeSingleFrameLinks(Environment *ev, ODStorageUnit *su, CCloneInfo *info)
- {
- // give our one shape an externalization index
- CShape *shape = (CShape *)fShapeList->First();
- shape->SetExternalizationIndex(0);
-
- // If we're exporting a single embedded frame, that has is a link source and/or destination
- // then the kODPropContents property belongs to the embedded part, which does not know about
- // the links maintained by its container. Use the kODPropProxyContents to write link data.
-
- // Focus to kODPropProxyContents and then call the ordinary ExternalizeLinks method.
- ODSUForceFocus(ev, su, kODPropProxyContents, kDrawEditorKind);
-
- this->ExternalizeLinks(ev, su, info);
- }
-
-
- #pragma segment Main
- void CDrawContent::MergeSingleFrameSubLink( Environment *ev, ODStorageUnit *su, CCloneInfo *info, COrderedList* shapeList, ODULong& offset)
- {
- if (su->Exists(ev, kODPropProxyContents, fDrawEditor->GetEditorKind(), 0))
- {
- su->Focus(ev, kODPropProxyContents, kODPosUndefined, fDrawEditor->GetEditorKind(), 0, kODPosUndefined);
- su->SetOffset(ev, offset);
-
- this->InternalizeSubLinks(ev, su, info, NULL); // NULL = there's no shape table
-
- offset = su->GetOffset(ev);
-
- // There should only be one subscriber link written for what was a single embedded frame
- CSubscribeLink *sLink = (CSubscribeLink *)fSubscribeLinks->First();
-
- if (sLink)
- {
- COrdListIterator iter(shapeList);
- for (CShape* shape = (CShape*)iter.First(); iter.IsNotComplete(); shape = (CShape*)iter.Next())
- {
- sLink->AddShape(ev,shape);
- }
- }
- }
- }
-
-
- #pragma segment Main
- void CDrawContent::MergeSingleFramePubLink( Environment *ev, ODStorageUnit *su, CCloneInfo *info, COrderedList* shapeList, ODULong& offset)
- {
- if (su->Exists(ev, kODPropProxyContents, fDrawEditor->GetEditorKind(), 0))
- {
- su->Focus(ev, kODPropProxyContents, kODPosUndefined, fDrawEditor->GetEditorKind(), 0, kODPosUndefined);
- su->SetOffset(ev, offset);
-
- this->InternalizePubLinks(ev, su, info, NULL); // NULL = there's no shape table
-
- offset = su->GetOffset(ev);
-
- // Normally, there is only one publisher for for what was a single embedded frame, BUT
- // If content was removed from a link, or a containing frame with a link was merged
- // into a single embedded frame withing that frame that had a link source, then we could
- // have more than one source link. Unfortuanately OpenDoc does not presently provide a way to
- // merge source links, so we may have many
-
- COrdListIterator iter(fPublishLinks);
- for (CPublishLink *pLink = (CPublishLink *)iter.First(); iter.IsNotComplete(); pLink = (CPublishLink *)iter.Next())
- {
- COrdListIterator iter(shapeList);
- for (CShape* shape = (CShape*)iter.First(); iter.IsNotComplete(); shape = (CShape*)iter.Next())
- {
- pLink->AddShape(ev, shape);
- }
- }
- }
- }
-
-
- #pragma segment Main
- void CDrawContent::InternalizeSubLinks( Environment *ev, ODStorageUnit *su, CCloneInfo *info, CShape** shapeTable)
- {
- ODUShort subCount;
- StorageUnitGetValue(su, ev, sizeof(ODUShort), &subCount);
-
- if (subCount == 0)
- return;
-
- if (!fSubscribeLinks || !fPublishLinks)
- {
- DebugStr("\pwe seem to have found links in LinkUpdated");
- return;
- }
-
- CSubscribeLink* sLink = kODNULL;
-
- for (long j = 0; j < subCount; j++)
- {
- if (!sLink)
- sLink = new CSubscribeLink(fDrawEditor->GetSelection());
-
- if (sLink->InternalizeLink(ev, su, info, shapeTable))
- {
- fSubscribeLinks->AddLast(sLink);
- sLink = kODNULL;
- }
-
- }
-
- if (sLink)
- delete sLink;
-
- }
-
-
- #pragma segment Main
- void CDrawContent::InternalizePubLinks( Environment *ev, ODStorageUnit *su, CCloneInfo *info, CShape** shapeTable)
- {
- ODUShort pubCount;
- StorageUnitGetValue(su, ev, sizeof(ODUShort), &pubCount);
-
- if (pubCount == 0)
- return;
-
- if (!fSubscribeLinks || !fPublishLinks)
- {
- DebugStr("\pwe seem to have found links in LinkUpdated");
- return;
- }
-
- CPublishLink* pLink = kODNULL;
-
- for (ODUShort j = 0; j < pubCount; j++)
- {
- if (!pLink)
- pLink = new CPublishLink(fDrawEditor->GetSelection());
-
- if (pLink->InternalizeLink(ev, su, info, shapeTable))
- {
- fPublishLinks->AddLast(pLink);
- pLink = kODNULL;
- }
-
- }
-
- if (pLink)
- delete pLink;
-
- }
-
-
- #pragma segment Main
- void CDrawContent::InternalizeSingleEmbeddedFrameLinks(Environment* ev, ODStorageUnit* su, CCloneInfo* info)
- {
- if (su->Exists(ev, kODPropProxyContents, fDrawEditor->GetEditorKind(), 0))
- {
- su->Focus(ev, kODPropProxyContents, kODPosUndefined, fDrawEditor->GetEditorKind(), 0, kODPosUndefined);
-
- this->InternalizeSubLinks(ev, su, info, NULL); // NULL = there's no shape table
- this->InternalizePubLinks(ev, su, info, NULL); // NULL = there's no shape table
- }
- }
-
-
- #pragma segment Main
- void CDrawContent::PostCloneInternalizeLinks(Environment* ev, CShape* shape)
- {
- ODDraft* toDraft = fDrawEditor->GetDraft(ev);
-
- COrderedList *scrapList = new COrderedList;
- CSubscribeLink *slink;
- CPublishLink *plink;
-
- // the only content object without these is CSubscribeLinkContent. We should never have
- // any links to deal with internalizing here.
- if (!fSubscribeLinks || !fPublishLinks)
- return;
-
- COrdListIterator sLinkIte(fSubscribeLinks);
- for (slink = (CSubscribeLink *)sLinkIte.First(); sLinkIte.IsNotComplete(); slink = (CSubscribeLink *)sLinkIte.Next())
- {
- if (slink->PostCloneInternalizeLink(ev, toDraft, shape))
- {
- this->AddSubscriberToPart(ev, slink);
- }
- else
- {
- scrapList->AddLast(slink);
- }
-
- }
-
- while (scrapList->Count() != 0)
- {
- slink = (CSubscribeLink *)scrapList->RemoveFirst();
- fSubscribeLinks->Remove(slink);
- delete slink;
- }
-
- COrdListIterator pLinkIte(fPublishLinks);
- for (plink = (CPublishLink *)pLinkIte.First(); pLinkIte.IsNotComplete(); plink = (CPublishLink *)pLinkIte.Next())
- {
- if (plink->PostCloneInternalizeLink(ev, toDraft, shape))
- {
- this->AddPublisherToPart(ev, plink);
- }
- else
- {
- scrapList->AddLast(plink);
- }
-
- }
-
- while (scrapList->Count() != 0)
- {
- plink = (CPublishLink *)scrapList->RemoveFirst();
- fPublishLinks->Remove(plink);
- delete plink;
- }
-
- delete scrapList;
- }
-
- #pragma segment Main
- void CDrawContent::AddPublisherToPart(Environment* ev, CPublishLink* pLink)
- {
- pLink->AddToPart(ev);
- }
-
-
- #pragma segment Main
- void CDrawContent::AddSubscriberToPart(Environment* ev, CSubscribeLink* sLink)
- {
- sLink->AddToPart(ev);
- }
-
-
-
-
-
- #pragma segment Main
-
-
-
-
-
-
-
- //=============================================================================
- // CPartContent
- //=============================================================================
-
-
- //-----------------------------------------------------------------------------
- // CPartContent::CPartContent
- //-----------------------------------------------------------------------------
-
- CPartContent::CPartContent(DrawEditor* editor, COrderedList* shapes, COrderedList* pLinks, COrderedList* sLinks) :
- CDrawContent(editor, shapes, pLinks, sLinks)
- {
- }
-
-
- //-----------------------------------------------------------------------------
- // CPartContent::~CPartContent
- //-----------------------------------------------------------------------------
-
- CPartContent::~CPartContent()
- {
- }
-
-
- //-----------------------------------------------------------------------------
- // CPartContent::AddShapeToPart
- //-----------------------------------------------------------------------------
-
- void CPartContent::AddShapeToPart(Environment *ev, CShape* shape)//Override
- {
- // The CPartContent object IS the Part content, so this method does nothing.
- }
-
- //-----------------------------------------------------------------------------
- // CPartContent::Add
- //-----------------------------------------------------------------------------
- void CPartContent::Add(Environment* ev, CShape* shape)
- {
- fDrawEditor->AddShape(ev, shape);
- }
-
- //-----------------------------------------------------------------------------
- // CPartContent::AddShape
- //-----------------------------------------------------------------------------
- void CPartContent::AddShape(Environment* ev, CShape* shape)
- {
- fDrawEditor->AddShape(ev, shape);
- }
-
-
- //-----------------------------------------------------------------------------
- // CPartContent::Externalize
- //-----------------------------------------------------------------------------
-
- void CPartContent::Externalize(Environment* ev,
- ODStorageUnit* storage,
- CCloneInfo* info)
- {
-
- // Externalize the part specific content first ( header )
- TRY
- // Write the tag constant identifying this as a selection
- // as opposed to a complete document. That is, data that is
- // normally be written out during an interchange operation, rather it is
- // only written out when the document is saved as a whole.
-
- StorageUnitSetValue(storage, ev, sizeof(ODSShort), &kDrawDocument);
-
- CATCH_ALL
- ODSetSOMException(ev, ErrorCode());
- ENDTRY
-
- // Next, continue externalization of intrinsic content
- CDrawContent::Externalize(ev, storage, info);
- }
-
- #pragma segment Main
- void CPartContent::AddPublisherToPart(Environment* ev, CPublishLink* pLink)//Override
- {
- // This content object "is" the part content, so don't need to add it
- // Do need to do the other function that goes with being added to the part.
-
- pLink->SetSourcePart(ev);
- }
-
-
- #pragma segment Main
- void CPartContent::AddSubscriberToPart(Environment* ev, CSubscribeLink* sLink)//Override
- {
- // Since this content object is the part content, don't call AddToPart, and add the link again
-
-
- // Currently, an update precipitated during InitPartFromStorage will cause CSelection::CalcUpdateShape
- // to fail due to lack of a facet.
-
- // Defer this and do it in DisplayFrameConnected.
- // sLink->Register(ev);
- }
-
-
-
- //=============================================================================
- // CPromiseContent
- //=============================================================================
-
-
- //-----------------------------------------------------------------------------
- // CPromiseContent::CPromiseContent
- // Initialize with same content as 'content'.
- //-----------------------------------------------------------------------------
-
- CPromiseContent::CPromiseContent(CDrawContent* content) :
- CDrawContent(content->GetDrawEditor())
- {
- fShapeList = new COrderedList(content->GetShapeList());
- fPublishLinks = new COrderedList(content->GetPublishLinks());
- fSubscribeLinks = new COrderedList(content->GetSubscribeLinks());
- }
-
-
- //-----------------------------------------------------------------------------
- // CPromiseContent::CPromiseContent
- //-----------------------------------------------------------------------------
- CPromiseContent::CPromiseContent(DrawEditor* editor, COrderedList* shapeList):
- CDrawContent(editor, shapeList, kODNULL, kODNULL)
- {
- }
-
-
- //-----------------------------------------------------------------------------
- // CPromiseContent::~CPromiseContent
- //-----------------------------------------------------------------------------
-
- CPromiseContent::~CPromiseContent()
- {
- delete fShapeList;
- delete fPublishLinks;
- delete fSubscribeLinks;
- }
-
- //-----------------------------------------------------------------------------
- // CPromiseContent::Externalize
- // Since we are only promising selections, externalize like a selection would
- //-----------------------------------------------------------------------------
- void CPromiseContent::Externalize(Environment* ev,
- ODStorageUnit* storage,
- CCloneInfo* info)
- {
- // Externalize the selection specific content first ( header )
- TRY
- // Write the tag constant identifying this as a selection
- // as opposed to a complete document
- StorageUnitSetValue(storage, ev, sizeof(ODSShort), &kDrawSelection);
- CATCH_ALL
- ODSetSOMException(ev, ErrorCode());
- ENDTRY
-
- // Next, continue externalization of intrinsic content
- CDrawContent::Externalize(ev, storage, info);
- }
-
-
- //-----------------------------------------------------------------------------
- // CPromiseContent::AddShapeToPart
- //-----------------------------------------------------------------------------
-
- void CPromiseContent::AddShapeToPart(Environment *ev, CShape* shape)
- {
- DebugStr("\pCPromiseContent can't AddShapeToPart");
- }
-
- //-----------------------------------------------------------------------------
- // CPromiseContent::AddShape
- //-----------------------------------------------------------------------------
- void CPromiseContent::AddShape(Environment *ev, CShape* shape)
- {
- DebugStr("\pCPromiseContent can't AddShape");
- }
-
- //-----------------------------------------------------------------------------
- // CSubscribeContent::Constructor
- //-----------------------------------------------------------------------------
- CSubscribeContent::CSubscribeContent(DrawEditor* editor, COrderedList* shapes, CSubscribeLink* subscribeLink) :
- CDrawContent(editor, shapes, kODNULL, kODNULL)
- {
- fSubscribeLink = subscribeLink;
- }
-
-
- //-----------------------------------------------------------------------------
- // CSubscribeContent::Destructor
- //-----------------------------------------------------------------------------
- CSubscribeContent::~CSubscribeContent()
- {
- }
-
-
- //-----------------------------------------------------------------------------
- // CSubscribeContent::AddShapeToPart
- //-----------------------------------------------------------------------------
- void CSubscribeContent::AddShapeToPart(Environment *ev, CShape* shape)//Override
- {
- fDrawEditor->AddShape(ev, shape);
- }
-
-
- //-----------------------------------------------------------------------------
- // CSubscribeContent::AddShape
- //-----------------------------------------------------------------------------
- void CSubscribeContent::AddShape(Environment *ev, CShape* shape)
- {
- fSubscribeLink->AddShape(ev, shape);
- }
-
-
- //-----------------------------------------------------------------------------
- // CSelectionContent::Constructor
- //-----------------------------------------------------------------------------
- CSelectionContent::CSelectionContent(DrawEditor* editor,
- COrderedList* shapes,
- COrderedList* pLinks,
- COrderedList* sLinks,
- CSelection* selection):
- CDrawContent(editor, shapes, pLinks, sLinks)
- {
- fSelection = selection;
- }
-
-
- //-----------------------------------------------------------------------------
- // CSelectionContent::Destructor
- //-----------------------------------------------------------------------------
- CSelectionContent::~CSelectionContent()
- {
- }
-
- //-----------------------------------------------------------------------------
- // CSelectionContent::Externalize
- //-----------------------------------------------------------------------------
- void CSelectionContent::Externalize(Environment* ev,
- ODStorageUnit* storage,
- CCloneInfo* info)
- {
- // Externalize the selection specific content first ( header )
- TRY
- // Write the tag constant identifying this as a selection
- // as opposed to a complete document
- StorageUnitSetValue(storage, ev, sizeof(ODSShort), &kDrawSelection);
- CATCH_ALL
- ODSetSOMException(ev, ErrorCode());
- ENDTRY
-
- // Next, continue externalization of intrinsic content
- CDrawContent::Externalize(ev, storage, info);
- }
-
-
- //-----------------------------------------------------------------------------
- // CSelectionContent::AddShapeToPart
- //-----------------------------------------------------------------------------
- void CSelectionContent::AddShapeToPart(Environment *ev, CShape* shape)//Override
- {
- fDrawEditor->AddShape(ev, shape);
- }
-
-
- //-----------------------------------------------------------------------------
- // CSelectionContent::AddShape
- //-----------------------------------------------------------------------------
- void CSelectionContent::AddShape(Environment *ev, CShape* shape)
- {
- fSelection->AddToSelection(ev, shape, kODTrue);
- }
- #pragma segment Main
- void CSelectionContent::AddSubscriberToPart(Environment* ev, CSubscribeLink* sLink)
- {
- // Calling sLink->AddToPart may cause instantaneous update. That would close the selection
- // emptying the very list that is being iterated to make this call.
-
- // The paste or drop command object must make a copy of that list
- // for purposes of undo/redo, and must iterate the copied list calling sLink->AddToPart
- // after internalization is complete.
- }
-